package io.github.eric.urpc.core.util;

import java.util.concurrent.ThreadLocalRandom;

public class RandomStringGenerator {

    private static final char[] CHARACTERS = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray();

    public static String genRandomString(int length) {
        if (length < 1) {
            throw new IllegalArgumentException("length must be greater than 0");
        }

        ThreadLocalRandom random = ThreadLocalRandom.current();
        char[] chars = new char[length];
        for (int i = 0; i < length; i++) {
            chars[i] = CHARACTERS[random.nextInt(CHARACTERS.length)];
        }
        return new String(chars);
    }

    public static void main(String[] args) {
        System.out.println(genRandomString(10));
    }
}